<?php
namespace app\api\model;

class UserTbOrder extends Base
{
    
    public function getRefundTagAttr($value)
    {
        //维权标签，0 含义为非维权 1 含义为维权订单
        $refund_tag = [
            0       =>      '正常订单',
            1       =>      '维权订单',
            
            ];
        return $refund_tag[$value];
    }

    public function getTkCreateTimeAttr($value)
    {


        return date('Y-m-d H:i',$value);
    }
    public function getPaidTimeAttr($value)
    {

        
        return date('Y-m-d H:i',$value);
    }
    /**
     * //解除订单绑定
     * 
     * 
     */ 
    public function del_order_bind($value)
    {
        $data=json_decode($value,true);
    
        //先查询
        $user = $this->where('robot_id', $data['robot_id'])->where('trade_parent_id', $data['order_id'])->find();
        //判断数据
        if($user){
            //有找到
            $res=$this->update(["id"=>$data['id'],"openid"=>Null]);
            if($res){
                //更新成功
                return ['code'=>1,'msg'=>'解除订单绑定成功'];
            }else{
                //更新失败
                return ['code'=>0,'msg'=>'解除订单绑定失败'];
            }
            
        }else {
            //没有找到
            return ['code'=>0,'msg'=>'提交参数异常'];
        }
     
    }
    
    /**
     * //订单绑定
     * 
     * array(5) { ["order_id"]=> string(19) "2027205002956530713" ["type"]=> int(1) ["robot_id"]=> string(15) "gh_80bb762dd2d9" ["openid"]=> string(13) "5555555555555" ["id"]=> int(531) }
     */ 
    public function order_bind($value)
    {
        $data=json_decode($value,true);
        //先查询
        $user = $this->where('robot_id', $data['robot_id'])->where('trade_parent_id', $data['order_id'])->find();
        //判断数据
        if($user){
            //有找到
            $res=$this->update(["id"=>$data['id'],"openid"=>$data['openid']]);
            if($res){
                //更新成功
                return ['code'=>1,'msg'=>'订单绑定成功'];
            }else{
                //更新失败
                return ['code'=>0,'msg'=>'订单绑定失败'];
            }
        }else {
            //没有找到
            return ['code'=>0,'msg'=>'提交参数异常'];
        }
    }
    
    /**
     * 解除订单冻结
     * 
     * string(81) "{"order_id":"2000359729276172156","type":1,"robot_id":"gh_80bb762dd2d9","id":527}"
     */ 
    public function del_order_thaw($value)
    {
        $data=json_decode($value,true);
        //先查询
        $user = $this->where('robot_id', $data['robot_id'])->where('trade_parent_id', $data['order_id'])->find();
        //判断数据
        if($user){
            //有找到
            $res=$this->update(["id"=>$data['id'],"fl_status"=>'已结算']);
            if($res){
                //更新成功
                return ['code'=>1,'msg'=>'解除订单冻结成功'];
            }else{
                //更新失败
                return ['code'=>0,'msg'=>'解除订单冻结失败'];
            }
        }else {
            //没有找到
            return ['code'=>0,'msg'=>'提交参数异常'];
        }
    }
    
     /**
     * //结算订单状态
     * 
     * {"order_id":"1370883829189820690","type":1,"robot_id":"gh_80bb762dd2d9","id":525}
     */ 
    public function order_pub($value)
    {
        $data=json_decode($value,true);
        //先查询
        $user = $this->where('robot_id', $data['robot_id'])->where('trade_parent_id', $data['order_id'])->find();
        //判断数据
        if($user){
            //有找到
            $res=$this->update(["id"=>$data['id'],"fl_status"=>'已结算']);
            if($res){
                //更新成功
                return ['code'=>1,'msg'=>'订单结算成功'];
            }else{
                //更新失败
                return ['code'=>0,'msg'=>'订单结算失败'];
            }
        }else {
            //没有找到
            return ['code'=>0,'msg'=>'提交参数异常'];
        }
    }
    
    /**
     * //退款订单状态
     * 
     * {"order_id":"2018929863742129602","type":1,"robot_id":"gh_80bb762dd2d9","id":524}
     */ 
    public function order_Inv($value)
    {
        $data=json_decode($value,true);
        //先查询
        $user = $this->where('robot_id', $data['robot_id'])->where('trade_parent_id', $data['order_id'])->find();
        //判断数据
        if($user){
            //有找到
            $res=$this->update(["id"=>$data['id'],"status"=>13,"fl_status"=>'已退款']);
            if($res){
                //更新成功
                return ['code'=>1,'msg'=>'订单结算成功'];
            }else{
                //更新失败
                return ['code'=>0,'msg'=>'订单结算失败'];
            }
        }else {
            //没有找到
            return ['code'=>0,'msg'=>'提交参数异常'];
        }
    }
    
    /**
     * //订单转绑用户
     * 
     * {"order_id":"2018929863742129602","type":1,"robot_id":"gh_80bb762dd2d9","id":524}
     */ 
    public function order_transfer($value)
    {
        $data=json_decode($value,true);
        //先查询
        $user = $this->where('robot_id', $data['robot_id'])->where('trade_parent_id', $data['order_id'])->find();
        //判断数据
        if($user){
            //有找到
            $res=$this->update(["id"=>$data['id'],"openid"=>$data['openid']]);
            if($res){
                //更新成功
                return ['code'=>1,'msg'=>'订单结算成功'];
            }else{
                //更新失败
                return ['code'=>0,'msg'=>'订单结算失败'];
            }
        }else {
            //没有找到
            return ['code'=>0,'msg'=>'提交参数异常'];
        }
    }
    

    
}